package io.ent.modules.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.ent.common.utils.PageUtils;
import io.ent.common.utils.Query;
import io.ent.modules.product.dao.ProductCasePicsDao;
import io.ent.modules.product.entity.ProductCasePicsEntity;
import io.ent.modules.product.po.ProductCaseInfoPicEntityIfPo;
import io.ent.modules.product.service.ProductCasePicsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("productCasePicsService")
public class ProductCasePicsServiceImpl extends ServiceImpl<ProductCasePicsDao, ProductCasePicsEntity> implements ProductCasePicsService {
    @Autowired
    private ProductCasePicsDao productCasePicsDao;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ProductCasePicsEntity> page = this.page(
                new Query<ProductCasePicsEntity>().getPage(params),
                new QueryWrapper<ProductCasePicsEntity>()
        );
        return new PageUtils(page);
    }

    @Override
    public List<ProductCasePicsEntity> getAllPics(int id,int picType) {
        QueryWrapper<ProductCasePicsEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("pic_id",id).eq("is_del",0).eq("pic_type",picType);
        return list(wrapper);
    }

    @Override
    public boolean updatePicIsDelById(int id) {
        ProductCasePicsEntity entity = new ProductCasePicsEntity();
        entity.setIsDel(1);
        UpdateWrapper<ProductCasePicsEntity> wrapper = new UpdateWrapper<>();
        wrapper.eq("id", id);
        return  update(entity, wrapper);
    }

    @Override
    public List<ProductCaseInfoPicEntityIfPo> getPics(int id, int picType) {
        return productCasePicsDao.getPics(id,picType);
    }

}
